package com.ede.roverhu.simplebackstage.Utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * Created by Rover on 2016/9/24 .
 * Email 357319517@qq.com
 * APP信息工具类
 */
public class AppInfoUtils {
    /**
     * 获取APP的版本名称
     * @param context 上下文
     * @return  版本号
     */
    public static String getAppVersionName(Context context){
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(),0);
            return  pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("error","get version error");
            //can`t reach
            return "";
        }
    }
    /**
     * 获取APP的版本号
     * @param context 上下文
     * @return  版本号
     */
    public static int getAppVersionCode(Context context){
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(),0);
            return  pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e("error","get version error");
            //can`t reach
            return 0 ;
        }
    }
}
